/*     */ package com.qmsk.business.order.cart.controller;
/*     */ 
/*     */ import com.qmsk.business.area.location.dao.LocationDAO;
/*     */ import com.qmsk.business.order.cart.dao.CartDAO;
/*     */ import com.qmsk.business.store.goods.dao.GoodsDAO;
/*     */ import com.qmsk.business.store.perfectGoods.dao.PerfectGoodsDAO;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.gson.out.GsonEbRstData;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.PrintStream;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"cart"})
/*     */ public class CartController
/*     */ {
/*  31 */   private Logger logger = Logger.getLogger(CartController.class);
/*     */ 
/*     */   @Autowired
/*     */   private CartDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private GoodsDAO goodsDAO;
/*     */ 
/*     */   @Autowired
/*     */   private LocationDAO locationDAO;
/*     */ 
/*     */   @Autowired
/*     */   private PerfectGoodsDAO perfectGoodsDAO;
/*     */ 
/*     */   @RequestMapping({"cartNums/{openId}"})
/*     */   public void queryCartNums(HttpServletRequest request, HttpServletResponse response, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/*  50 */       int count = this.dao.queryCartNums(openId);
/*     */ 
/*  52 */       ResponseUtils.toGsonEbRst(new String[] { "count" }, 
/*  53 */         new Object[] { Integer.valueOf(count) }, response);
/*     */     }
/*     */     catch (Exception e) {
/*  56 */       this.logger.error(e);
/*  57 */       ResponseUtils.setErrorMsgResponse(
/*  58 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping({"add/{shopId}/{goodsId}/{openId}"})
/*     */   public void add(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("goodsId") Long goodsId, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/*  69 */       int num = RequestUtils.getInt(request, "num", Integer.valueOf(0)).intValue();
/*     */ 
/*  71 */       GsonHeadOneRow row = this.dao.checkGoodsExist(goodsId, openId);
/*     */ 
/*  73 */       if ((row != null) && (row.getDataLength() > 0)) {
/*  74 */         Object cartId = row.getValueOfName("cartId");
/*  75 */         Integer oldNum = (Integer)row.getValueOfName("num");
/*  76 */         Float price = (Float)row.getValueOfName("price");
/*  77 */         Integer integral = (Integer)row.getValueOfName("integral");
/*  78 */         num = oldNum.intValue() + num;
/*  79 */         String[] head = { "num", "subTotal", 
/*  80 */           "subTtalIntegral", "cartId" };
/*  81 */         Object[] list = { Integer.valueOf(num), Float.valueOf(num * price.floatValue()), 
/*  82 */           Integer.valueOf(num * integral.intValue()), cartId };
/*     */ 
/*  84 */         row = new GsonHeadOneRow(head, list);
/*     */ 
/*  86 */         int n = this.dao.updateJsonHeadOneRow(row, "crm_cart");
/*  87 */         if (n <= 0) {
/*  88 */           ResponseUtils.setErrorMsgResponse("娣诲姞澶辫触锛�", response);
/*  89 */           DbConnection.rollback();
/*  90 */           return;
/*     */         }
/*  92 */         ResponseUtils.setSuccessResponse(response);
/*  93 */         DbConnection.commit();
/*  94 */         return;
/*     */       }
/*     */ 
/*  99 */       String[] head = { "goodsId", "openId", "shopId", 
/* 100 */         "num", "integral", "subTtalIntegral", "price", "subTotal", 
/* 101 */         "createFileTime", "status" };
/*     */ 
/* 103 */       GsonHeadOneRow priceInfo = this.goodsDAO
/* 104 */         .getGoodsSalePriceAndIntegral(goodsId);
/* 105 */       Double SalePrice = null;
/* 106 */       Double SaleIntegral = null;
/*     */       try {
/* 108 */         SalePrice = Double.valueOf(Double.parseDouble(priceInfo.getValueOfName("salePrice")
/* 109 */           .toString()));
/* 110 */         SaleIntegral = Double.valueOf(Double.parseDouble(priceInfo.getValueOfName("saleIntegral")
/* 111 */           .toString()));
/*     */       }
/*     */       catch (Exception e) {
/* 114 */         e.printStackTrace();
/*     */       }
/*     */ 
/* 117 */       if ((SalePrice == null) || (SaleIntegral == null)) {
/* 118 */         ResponseUtils.setErrorMsgResponse("娌℃湁鎵惧埌鍟嗗搧锛�", response);
/* 119 */         DbConnection.rollback();
/* 120 */         return;
/*     */       }
/*     */ 
/* 123 */       Object[] list = { goodsId, openId, shopId, Integer.valueOf(num), 
/* 124 */         SaleIntegral, Double.valueOf(SaleIntegral.doubleValue() * num), SalePrice, 
/* 125 */         Double.valueOf(SalePrice.doubleValue() * num), new Date(), Integer.valueOf(0) };
/*     */ 
/* 127 */       row = new GsonHeadOneRow(head, list);
/* 128 */       int n = this.dao.insertGsonHeadOneRow(row);
/* 129 */       if (n <= 0) {
/* 130 */         ResponseUtils.setErrorMsgResponse("娣诲姞璐墿杞﹀け璐ワ紒", response);
/* 131 */         DbConnection.rollback();
/* 132 */         return;
/*     */       }
/*     */ 
/* 135 */       DbConnection.commit();
/* 136 */       ResponseUtils.setSuccessResponse(response);
/* 137 */       return;
/*     */     } catch (Exception e) {
/* 139 */       DbConnection.rollback();
/* 140 */       e.printStackTrace();
/* 141 */       this.logger.error(e);
/* 142 */       ResponseUtils.setErrorMsgResponse(
/* 143 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping({"edit/{cartId}/{num}"})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("cartId") Long cartId, @PathVariable("num") Integer num)
/*     */   {
/*     */     try
/*     */     {
/* 153 */       if ((num == null) || (num.intValue() <= 0)) {
/* 154 */         ResponseUtils.setErrorMsgResponse("璇疯緭鍏ユ纭殑鏁板�硷紒", response);
/* 155 */         return;
/*     */       }
/*     */ 
/* 158 */       GsonHeadOneRow row = this.dao.findCartNum(cartId);
/*     */ 
/* 160 */       if ((row == null) || (row.getDataLength() <= 0)) {
/* 161 */         ResponseUtils.setErrorMsgResponse("璇ヨ鍗曢」涓嶅瓨鍦紒", response);
/* 162 */         return;
/*     */       }
/* 164 */       Float price = (Float)row.getValueOfName("price");
/* 165 */       Integer integral = (Integer)row.getValueOfName("integral");
/* 166 */       String[] head = { "num", "subTotal", 
/* 167 */         "subTtalIntegral", "cartId" };
/* 168 */       Object[] list = { num, Float.valueOf(num.intValue() * price.floatValue()), Integer.valueOf(num.intValue() * integral.intValue()), 
/* 169 */         cartId };
/*     */ 
/* 171 */       row = new GsonHeadOneRow(head, list);
/*     */ 
/* 173 */       int n = this.dao.updateJsonHeadOneRow(row, "crm_cart");
/* 174 */       if (n <= 0) {
/* 175 */         ResponseUtils.setErrorMsgResponse("娣诲姞澶辫触锛�", response);
/* 176 */         DbConnection.rollback();
/* 177 */         return;
/*     */       }
/* 179 */       ResponseUtils.setSuccessResponse(response);
/* 180 */       DbConnection.commit();
/*     */     }
/*     */     catch (Exception e) {
/* 183 */       DbConnection.rollback();
/* 184 */       this.logger.error(e);
/* 185 */       ResponseUtils.setErrorMsgResponse(
/* 186 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping({"list/{openId}"})
/*     */   public void list(HttpServletRequest request, HttpServletResponse response, @PathVariable("openId") String openId)
/*     */   {
/*     */     try {
/* 194 */       GsonEbRst rst = this.dao.getcartGoodsList(openId);
/* 195 */       ResponseUtils.setResponseResult(rst, response);
/*     */     }
/*     */     catch (Exception e) {
/* 198 */       DbConnection.rollback();
/* 199 */       this.logger.error(e.getMessage());
/* 200 */       ResponseUtils.setErrorMsgResponse(
/* 201 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping({"receiveInfo/{openId}"})
/*     */   public void getReceiveInfo(HttpServletRequest request, HttpServletResponse response, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/* 220 */       GsonHeadOneRow row = this.dao.getReceiveInfo(openId);
/*     */ 
/* 225 */       if ((row == null) || (row.getDataLength() == 0)) {
/* 226 */         GsonEbRst rst = GsonHeadOneRowToGsonEbRst(row);
/* 227 */         ResponseUtils.setResponseResult(rst, response);
/* 228 */         return;
/*     */       }
/*     */ 
/* 234 */       Object location = row.getValueOfName("location");
/* 235 */       if (location == null)
/*     */       {
/* 239 */         GsonEbRst rst = GsonHeadOneRowToGsonEbRst(row);
/* 240 */         ResponseUtils.setResponseResult(rst, response);
/* 241 */         return;
/*     */       }
/*     */ 
/* 244 */       GsonHeadOneRow locationInfo = this.locationDAO.getLocationInfo(location);
/*     */ 
/* 246 */       if ((locationInfo == null) || (locationInfo.getDataLength() == 0))
/*     */       {
/* 250 */         GsonEbRst rst = GsonHeadOneRowToGsonEbRst(row);
/* 251 */         ResponseUtils.setResponseResult(rst, response);
/* 252 */         return;
/*     */       }
/*     */ 
/* 258 */       row.addHeadData(locationInfo.getHead(), locationInfo.getData());
/* 259 */       GsonEbRst rst = GsonHeadOneRowToGsonEbRst(row);
/* 260 */       ResponseUtils.setResponseResult(rst, response);
/*     */     }
/*     */     catch (Exception e) {
/* 263 */       DbConnection.rollback();
/* 264 */       e.printStackTrace();
/* 265 */       this.logger.error(e.getMessage());
/* 266 */       ResponseUtils.setErrorMsgResponse(
/* 267 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   public GsonEbRst GsonHeadOneRowToGsonEbRst(GsonHeadOneRow row)
/*     */   {
/* 279 */     GsonEbRst rst = new GsonEbRst();
/* 280 */     GsonEbRstData data = new GsonEbRstData();
/* 281 */     rst.setResult(data);
/*     */ 
/* 283 */     if ((row != null) && (row.getDataLength() != 0)) {
/* 284 */       data.setHead(row.getHead());
/* 285 */       List list = new ArrayList();
/* 286 */       list.add(row.getData());
/* 287 */       data.setData(list);
/* 288 */       data.setLen(Long.valueOf(1L));
/*     */     }
/* 290 */     return rst;
/*     */   }
/*     */ 
/*     */   @RequestMapping({"del/{cartId}"})
/*     */   public void del(HttpServletRequest request, HttpServletResponse response, @PathVariable("cartId") Long cartId)
/*     */   {
/*     */     try {
/* 297 */       int n = this.dao.deleteParams(new Object[] { cartId });
/* 298 */       if (n <= 0) {
/* 299 */         ResponseUtils.setErrorMsgResponse("鍒犻櫎澶辫触锛�", response);
/* 300 */         DbConnection.rollback();
/* 301 */         return;
/*     */       }
/* 303 */       DbConnection.commit();
/* 304 */       ResponseUtils.setSuccessResponse(response);
/* 305 */       return;
/*     */     } catch (Exception e) {
/* 307 */       DbConnection.rollback();
/* 308 */       this.logger.error(e);
/* 309 */       ResponseUtils.setErrorMsgResponse(
/* 310 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   public static void main(String[] args) {
/* 315 */     String str = "o_m_Kjkzi2B43se1mBKciVXlOWmw";
/* 316 */     System.out.println(str.length());
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\鏂板缓鏂囦欢澶筡WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.order.cart.controller.CartController
 * JD-Core Version:    0.5.3
 */